#!/usr/bin/env python3
import re

with open('src/plugins/Makefile.am', 'r', encoding='utf-8') as f:
    content = f.read()

# 修复重复定义问题
patterns = [
    (r'if BUILD_CONFIGMANAGER_IMPORTERS\nMAYBE_CONFIGMANAGER_IMPORTERS = configmanager_importers\nendif.*?if BUILD_CONFIGMANAGER_IMPORTERS', 
     r'if BUILD_CONFIGMANAGER_IMPORTERS\nMAYBE_CONFIGMANAGER_IMPORTERS = configmanager_importers\nendif'),
    (r'if BUILD_CONFIGMANAGER_EXPORTERS\nMAYBE_CONFIGMANAGER_EXPORTERS = configmanager_exporters\nendif.*?if BUILD_CONFIGMANAGER_EXPORTERS', 
     r'if BUILD_CONFIGMANAGER_EXPORTERS\nMAYBE_CONFIGMANAGER_EXPORTERS = configmanager_exporters\nendif')
]

for pattern, replacement in patterns:
    content = re.sub(pattern, replacement, content, flags=re.DOTALL)

# 修复复杂的条件定义
content = re.sub(r'if BUILD_CONFIGMANAGER\nMAYBE_CONFIGMANAGER = configmanager\nendif\nif BUILD_CONFIGMANAGER\nMAYBE_CONFIGMANAGER_COMMON = configmanager_common\nendif', 
                 r'if BUILD_CONFIGMANAGER\nMAYBE_CONFIGMANAGER = configmanager\nMAYBE_CONFIGMANAGER_COMMON = configmanager_common\nendif', content)

with open('src/plugins/Makefile.am', 'w', encoding='utf-8') as f:
    f.write(content)

print("Makefile.am修复完成")
